<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateStationTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('station_class', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name',64)->default('')->comment('岗位分类名称');
            $table->string('created_user',64)->default('')->comment('创建人');
            $table->string('updated_user',64)->default('')->comment('修改人');
            $table->timestamps();
        });

        Schema::create('station', function (Blueprint $table) {
            $table->increments('id');
            $table->bigInteger('station_class_id')->comment('岗位分类ID');
            $table->bigInteger('role_id')->unsigned()->nullable()->comment('角色ID');
            $table->string('name','64')->default('')->comment('岗位名称');
            $table->bigInteger('order_no')->default('0')->comment('岗位排序');
            $table->string('created_user',64)->default('')->comment('创建人');
            $table->string('updated_user',64)->default('')->comment('修改人');

            $table->timestamps();
        });

        Schema::create('user_station', function (Blueprint $table) {
            $table->bigInteger('user_id')->unsign()->comment('用户id');
            $table->bigInteger('station_id')->unsign()->comment('岗位id');
            $table->string('type')->default('assist')->unsign()->comment('类型 参看系统代码USER_STATION_TYPE');
            $table->string('created_user',64)->default('')->comment('创建人');
            $table->primary(['user_id', 'station_id']);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('station_class');
        Schema::drop('station');
        Schema::drop('user_station');
    }
}
